/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Kampania_Kontroler.java
 *
 * Created on 2010-06-03, 16:58:03
 */

package adbus;

import adbus.models.*;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *klasa odpowiedzialna z wyswietlanie okna dodania lini
 * i obsluge zdarzen z nim zwiazanych
 * @author rafal
 */
public class Linia_Kontroler extends javax.swing.JDialog {
    private Linia line = new Linia();
    private LiniaTable linesTable = null;

    /** Creates new form Kampania_Kontroler */
    public Linia_Kontroler(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
/**dwuargumentowy konstruktor klasy linia_Kontener*/
    public Linia_Kontroler(JFrame mainFrame, LiniaTable lTable) {
        super(mainFrame,true);
        initComponents();
        linesTable = lTable;
    }
/**trzyargumentowy konstruktor klasy Linia_Kontener*/
    public Linia_Kontroler(JFrame mainFrame, LiniaTable lTable, Linia linia) {
        super(mainFrame,true);
        line = linia;
        linesTable = lTable;
        initComponents();
        ((PrzewoznikList)lineCarrier.getModel()).setSelectedItem(line.przewoznik());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lineNumberLabel = new javax.swing.JLabel();
        lineCarrierLabel = new javax.swing.JLabel();
        lineCarrier = new javax.swing.JComboBox();
        cancelButton = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        lineDaily = new javax.swing.JCheckBox();
        lineNightly = new javax.swing.JCheckBox();
        lineWorkday = new javax.swing.JCheckBox();
        lineWeekend = new javax.swing.JCheckBox();
        lineInformation = new javax.swing.JTextField();
        lineInformationLabel = new javax.swing.JLabel();
        lineNumber = new javax.swing.JTextField();
        lineLinkLabel = new javax.swing.JLabel();
        lineLink = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adbus.AdBusApp.class).getContext().getResourceMap(Linia_Kontroler.class);
        lineNumberLabel.setText(resourceMap.getString("lineNumberLabel.text")); // NOI18N
        lineNumberLabel.setName("lineNumberLabel"); // NOI18N

        lineCarrierLabel.setText(resourceMap.getString("lineCarrierLabel.text")); // NOI18N
        lineCarrierLabel.setName("lineCarrierLabel"); // NOI18N

        lineCarrier.setModel(new adbus.models.PrzewoznikList());
        lineCarrier.setName("lineCarrier"); // NOI18N

        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        lineDaily.setSelected(line.dzienny);
        lineDaily.setText(resourceMap.getString("lineDaily.text")); // NOI18N
        lineDaily.setName("lineDaily"); // NOI18N

        lineNightly.setSelected(line.nocny);
        lineNightly.setText(resourceMap.getString("lineNightly.text")); // NOI18N
        lineNightly.setName("lineNightly"); // NOI18N

        lineWorkday.setSelected(line.robocze);
        lineWorkday.setText(resourceMap.getString("lineWorkday.text")); // NOI18N
        lineWorkday.setName("lineWorkday"); // NOI18N

        lineWeekend.setSelected(line.weekendy);
        lineWeekend.setText(resourceMap.getString("lineWeekend.text")); // NOI18N
        lineWeekend.setName("lineWeekend"); // NOI18N

        lineInformation.setText(line.uwagi);
        lineInformation.setName("lineInformation"); // NOI18N

        lineInformationLabel.setText(resourceMap.getString("lineInformationLabel.text")); // NOI18N
        lineInformationLabel.setName("lineInformationLabel"); // NOI18N

        lineNumber.setText(line.nr_lini);
        lineNumber.setName("lineNumber"); // NOI18N

        lineLinkLabel.setText(resourceMap.getString("lineLinkLabel.text")); // NOI18N
        lineLinkLabel.setName("lineLinkLabel"); // NOI18N

        lineLink.setText(line.link);
        lineLink.setName("lineLink"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextField1.setText(line.trasa);
        jTextField1.setName("jTextField1"); // NOI18N
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lineLinkLabel)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(cancelButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lineNumberLabel)
                                    .addComponent(lineCarrierLabel)
                                    .addComponent(lineInformationLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lineInformation, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(lineNumber, javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lineCarrier, javax.swing.GroupLayout.Alignment.TRAILING, 0, 226, Short.MAX_VALUE)
                                        .addComponent(lineDaily)
                                        .addComponent(lineNightly)
                                        .addComponent(lineWeekend)
                                        .addComponent(lineWorkday)
                                        .addComponent(lineLink, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
                                        .addComponent(jTextField1)))))
                        .addGap(38, 38, 38))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(353, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lineNumberLabel)
                    .addComponent(lineNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lineCarrierLabel)
                    .addComponent(lineCarrier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lineDaily)
                .addGap(3, 3, 3)
                .addComponent(lineNightly)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lineWorkday)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lineWeekend)
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lineLinkLabel)
                    .addComponent(lineLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lineInformationLabel)
                    .addComponent(lineInformation, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(okButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**metoda odpowiedzialna za obsluge przycisku Ok*/
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        line.nr_lini = lineNumber.getText();

        line.przypiszPrzewoznika((Przewoznik) lineCarrier.getSelectedItem());

        line.dzienny = lineDaily.isSelected();
        line.nocny = lineNightly.isSelected();
        line.robocze = lineWorkday.isSelected();
        line.weekendy = lineWeekend.isSelected();
        line.link = lineLink.getText();
        line.uwagi = lineInformation.getText();
        line.trasa = jTextField1.getText();
        line.zapisz();
        if(linesTable!=null) {
            linesTable.zaladuj();
        }
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed
/**metoda odpowiedzialna za obsluge przycisku aluluj*/
    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Linia_Kontroler dialog = new Linia_Kontroler(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JComboBox lineCarrier;
    private javax.swing.JLabel lineCarrierLabel;
    private javax.swing.JCheckBox lineDaily;
    private javax.swing.JTextField lineInformation;
    private javax.swing.JLabel lineInformationLabel;
    private javax.swing.JTextField lineLink;
    private javax.swing.JLabel lineLinkLabel;
    private javax.swing.JCheckBox lineNightly;
    private javax.swing.JTextField lineNumber;
    private javax.swing.JLabel lineNumberLabel;
    private javax.swing.JCheckBox lineWeekend;
    private javax.swing.JCheckBox lineWorkday;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables

   
    //private Kampania campaign = new Kampania();
}
